package com.zjitc.pigspring.config;

import com.zjitc.pigspring.job.BackUpSqlJob;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.quartz.*;


@Component
public class JobInit {

    @Autowired
    private Scheduler scheduler;

    @PostConstruct
    public void backUpSql() throws SchedulerException {

        JobDetail job = JobBuilder.newJob(BackUpSqlJob.class)
                .build();

        CronTrigger trigger = TriggerBuilder.newTrigger()
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("30 10 * * * ?"))
                .build();
        scheduler.scheduleJob(job,trigger);
    }
}
